﻿using NodaTime;
using System;

namespace ThresholdAssistant.DataContract.Extensions
{
    /// <summary>
    /// 自定义枚举扩展
    /// </summary>
    static class DateTimeExtensions
    {
        /// <summary>
        /// 解决Windows和linux系统市区问题
        /// </summary>
        /// <param name="dateTime">时间对象</param>
        /// <returns></returns>
        public static DateTime ToCstTime(this DateTime dateTime)
        {
            Instant now = SystemClock.Instance.GetCurrentInstant();
            var shanghaiZone = DateTimeZoneProviders.Tzdb["Asia/Shanghai"];
            return now.InZone(shanghaiZone).ToDateTimeUnspecified();
        }
    }
}